<?php
namespace app\admin\controller;
use think\Db;
/**
 * 用户管理
 * Class Member
 */
class MemberController extends BaseController {

//  protected function _initialize() {
//      parent::_initialize();
//  }

    /**
     * 用户管理
     * @param string $keyword
     * @param int    $page
     * @return mixed
     */
    public function index(){
    	$list=db('member')->order('id asc')->paginate(10);
    	$this->assign('list',$list);
        return $this->fetch();
    }

    
    public function add() {
    	if ($this->request->isPost()) {
         	$data=get_query()['query'];
            $data['password']=md5_salt(input('password'));
            $data['add_time']=now_time();
            if (db('member')->insert($data)) {
                exit(json_encode(array('status'=>1,'mag'=>'添加成功')));
            } else {
                exit(json_encode(array('status'=>0,'mag'=>'添加失败')));
            }
         }
        return $this->fetch();
    }

    /**
     * 编辑用户
     * @param $id
     * @return mixed
     */
    public function edit($id) {
    	 if ($this->request->isPost()) {
    	    $data=get_query()['query'];
            $data['password']=md5_salt(input('password'));
            $data['add_time']=now_time();
            $data['sex']=input('sex');
           if (db("member")->update($data) !== false) {
                $this->success('更新成功',url('index'));
            } else {
                $this->error('更新失败',url('index'));
            }
        
        }
        $member =db("member")->find($id);
        return $this->fetch('edit', ['member' => $member]);
    }

    
}
